import { currentUserID } from "@/utils/common.js";
import { utils } from 'hi-ui';
//验收入库数据集配置
export default {
    id: "SupervisioncodeEntity_out",
    modelFile: "supervisioncode/dataset/SupervisioncodeEntity_out.xml",
    //主从配置
    relation: {
        selfField: ["FBARCODE", 'FNUMBER', "FSHOPDESC", "FSHOPDESCID"],
        parentField: ["FBARCODE", 'FNUMBER', "FSHOPDESC", "FSHOPDESCID"]
    },
    sortFields: [
        "FID",
        "FSUPERVISIONCODE",
        "FBARCODE",
        "FNUMBER",
        "FUSERDESC",
        "FUSERID",
        "FCREATEDATE",
        "FENTERPRISEDESC",
        "FENTERPRISEID",
        "FSHOPDESC",
        "FSHOPDESCID"
    ],
    fields: {
        FID: {
            name: "FID", //字段ID
            label: "ID", //字段描述
            dbtype: "dbString", //数据类型
            default: {
                //默认值
                //rule: 'first', //prior   填充规则
                exps: (data) => {
                    //填充表达式
                    return utils.string.guid();
                },
            },
        },


        FSUPERVISIONCODE: {
            name: "FSUPERVISIONCODE", //字段ID
            label: "电子监管码", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },
        FBARCODE: {
            name: "FBARCODE", //字段ID
            label: "条形码", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },
        FUSERDESC: {
            name: "FUSERDESC", //字段ID
            label: "创建人", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },
        FNUMBER: {
            name: "FNUMBER", //字段ID
            label: "单号", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },
        FDESC: {
            name: "FDESC", //字段ID
            label: "通用名称", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },
        FUSERID: {
            name: "FUSERID", //字段ID
            label: "创建人", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
            default: {
                //默认值
                exps: (data) => {
                    //填充表达式
                    return currentUserID();
                },
            },
        },

        FCREATEDATE: {
            name: "FCREATEDATE", //字段ID
            label: "创建时间", //字段描述
            dbtype: "dbDate", //数据类型
            required: true,
            readonly: true,
            default: {
                //默认值
                exps: (data) => {
                    //填充表达式
                    return utils.date.format(new Date(), "yyyy-MM-dd HH:mm:ss");
                },
            },
        },



        FSHOPDESC: {
            name: "FSHOPDESC", //字段ID
            label: "店铺", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
            required: true,
        },
        FSHOPDESCID: {
            name: "FSHOPDESCID", //字段ID
            label: "店铺编号", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
            required: true,
        },

        FENTERPRISEDESC: {
            name: "FENTERPRISEDESC", //字段ID
            label: "企业名称", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },
        FENTERPRISEID: {
            name: "FENTERPRISEID", //字段ID
            label: "企业ID", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },

    },

}


export let updateSupervisioncode_out_audit = function (model, subStoreID, thirdStoreID) {
    debugger;
    //取子数据集
    let subDataSet = model.getChildStore(subStoreID);
    let data = subDataSet.data;
    //循环子数据集的数据
    for (let i = 0; i < data.length; i++) {
        let subModel = subDataSet.getModel(data[i]);
        if (!thirdStoreID) {
            subModel.set({ "FAUDIT": 0 });
        }
        else {
            //找到孙数据集
            let thirdDataset = subModel.getChildStore(thirdStoreID);
            let thirdData = thirdDataset.data;
            //循环孙数据集的数据
            for (let j = 0; j < thirdData.length; j++) {
                let thirdModel = thirdDataset.getModel(thirdData[j]);
                //更新孙数据集的数据
                thirdModel.set({ "FAUDIT": 0 });

            }
        }

    }
}